package com.zz.tijian.controller;


import com.zz.tijian.entity.Topic;
import com.zz.tijian.entity.req.AddReplyDto;
import com.zz.tijian.entity.req.AddTopicDto;
import com.zz.tijian.entity.req.TopicDto;
import com.zz.tijian.entity.res.ReplyVo;
import com.zz.tijian.entity.res.Result;
import com.zz.tijian.service.ReplyService;
import com.zz.tijian.service.TopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "大众询问")
@RestController
@RequestMapping("/reply")
@CrossOrigin
public class ReplyController {

    @Autowired
    private TopicService topicService;
    @Autowired
    private ReplyService replyService;

    /*
    搜索接口
     */
    @ApiOperation("获取讨论话题")
    @GetMapping("/getTopic")
    public Result<List<Topic>> getTopic( TopicDto topicDto){
        return topicService.getTopic(topicDto);
    }
    @ApiOperation("根据ID获取某个讨论话题")
    @GetMapping("/getTopicById/{topicId}")
    public Result<Topic> getTopicById(@PathVariable Integer topicId){
        return topicService.getTopicById(topicId);
    }

    @ApiOperation("添加新的话题讨论")
    @PostMapping("/addTopic")
    public Result<Boolean> addTopic(@RequestBody AddTopicDto addTopicDto){
        return topicService.addTopic(addTopicDto);
    }
    @ApiOperation("根据话题Id获取评论区列表")
    @GetMapping("/getTopicReplies/{topicId}")
    public Result<List<ReplyVo>> getTopicReplies(@PathVariable Integer topicId) {

        return replyService.buildReplyTree(topicId);

    }
    @ApiOperation("添加新的评论")
    @PostMapping("/addReply")
    public Result<Boolean>addReply(@RequestBody AddReplyDto addReplyDto){
        return replyService.addReply(addReplyDto);
    }

}


